<?php

class Validation {

	//Privata variabler.
	private $inputPassword = "Password1";
	private $inputusername = "username";
	Private $inputPasswordSecond = "Password2";
	private $errorMessages = array();
	//Funktion som validerar ett lösenord.

	public function ValidatePassword($inputPassword, $inputPasswordSecond) {
		$RegisterView = new RegisterView();
		var_dump($inputPassword);
		var_dump($inputPasswordSecond);
		if (preg_match("/^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/", $inputPassword)) {
			if ($inputPassword == $inputPasswordSecond) {
				return true;
			}
		} else {
			$this -> errorMessages[] = $RegisterView -> WrongPasswordMessage();
			return false;
		}

	}

	public function ValidateUserName($inputusername) {
		$RegisterView = new RegisterView();

		if (preg_match("/^[a-zA-Z0-9]+([a-zA-Z0-9](_|-| )[a-zA-Z0-9])*[a-zA-Z0-9]+$/", $inputusername)) {
			return true;

		} else {
			$this -> errorMessages[] = $RegisterView -> WrongUsernameMessage();
			return false;
		}

	}

	public function ShowErrorMessages() {
		$validationErrors = "";
		foreach ($this->errorMessages as $error) {
			$validationErrors .= $error;
		}
		return $validationErrors;
	}

}
